<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="承包商名称" prop="contractorName">
        <el-input
          v-model="queryParams.contractorName"
          placeholder="请输入承包商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="统一社会信用代码" prop="contractorCode">
        <el-input
          v-model="queryParams.contractorCode"
          placeholder="请输入统一社会信用代码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="注册地址" prop="registerAddress">
        <el-input
          v-model="queryParams.registerAddress"
          placeholder="请输入注册地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="实际办公地址" prop="officeAddress">
        <el-input
          v-model="queryParams.officeAddress"
          placeholder="请输入实际办公地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="企业法人" prop="legalPerson">
        <el-input
          v-model="queryParams.legalPerson"
          placeholder="请输入企业法人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="注册资本" prop="registeredCapital">
        <el-input
          v-model="queryParams.registeredCapital"
          placeholder="请输入注册资本"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="联系人" prop="contactPerson">
        <el-input
          v-model="queryParams.contactPerson"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="联系电话" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="经营范围" prop="businessScope">
        <el-input
          v-model="queryParams.businessScope"
          placeholder="请输入经营范围"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="管理部门" prop="managementDept">
        <el-input
          v-model="queryParams.managementDept"
          placeholder="请输入管理部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="管理部门联系人" prop="managementPerson">
        <el-input
          v-model="queryParams.managementPerson"
          placeholder="请输入管理部门联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="营业执照" prop="licenseFileId">
        <el-input
          v-model="queryParams.licenseFileId"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="营业执照" prop="licenseFileUrl">
        <el-input
          v-model="queryParams.licenseFileUrl"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="营业执照" prop="licenseFileName">
        <el-input
          v-model="queryParams.licenseFileName"
          placeholder="请输入营业执照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="拉黑状态" prop="isBlack">
        <el-select
          v-model="queryParams.isBlack"
          placeholder="请选择拉黑状态"
          clearable
          @change="handleQuery"
        >
          <el-option
            v-for="item in isBlackOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:contractor:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handle"
        >二维码</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handle"
        >准入考核</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:contractor:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:contractor:remove']"
        >删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:contractor:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="contractorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="id" />
      <el-table-column label="承包商名称" align="center" prop="contractorName" />
      <el-table-column label="统一社会信用代码" align="center" prop="contractorCode" />
      <el-table-column label="注册地址" align="center" prop="registerAddress" />
      <el-table-column label="实际办公地址" align="center" prop="officeAddress" />
      <el-table-column label="企业法人" align="center" prop="legalPerson" />
      <el-table-column label="注册资本" align="center" prop="registeredCapital" />
      <el-table-column label="联系人" align="center" prop="contactPerson" />
      <el-table-column label="联系电话" align="center" prop="contactPhone" />
      <el-table-column label="企业类型" align="center" prop="enterpriseType" />
      <el-table-column label="经营范围" align="center" prop="businessScope" />
      <el-table-column label="管理部门" align="center" prop="managementDept" />
      <el-table-column label="管理部门联系人" align="center" prop="managementPerson" />
      <el-table-column label="营业执照" align="center" prop="licenseFileId" />
      <el-table-column label="营业执照" align="center" prop="licenseFileUrl" />
      <el-table-column label="营业执照" align="center" prop="licenseFileName" />
      <el-table-column label="审核状态" align="center" prop="status" />
      <el-table-column label="拉黑状态" align="center" prop="isBlack">
        <template slot-scope="scope">
          <span v-if="scope.row.isBlack === 1">拉黑</span>
          <span v-else-if="scope.row.isBlack === 0">正常</span>
          <span v-else>{{ scope.row.isBlack }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:contractor:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:contractor:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改承包商信息对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="承包商名称" prop="contractorName">
          <el-input v-model="form.contractorName" placeholder="请输入承包商名称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="contractorCode">
          <el-input v-model="form.contractorCode" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="注册地址" prop="registerAddress">
          <el-input v-model="form.registerAddress" placeholder="请输入注册地址" />
        </el-form-item>
        <el-form-item label="实际办公地址" prop="officeAddress">
          <el-input v-model="form.officeAddress" placeholder="请输入实际办公地址" />
        </el-form-item>
        <el-form-item label="企业法人" prop="legalPerson">
          <el-input v-model="form.legalPerson" placeholder="请输入企业法人" />
        </el-form-item>
        <el-form-item label="注册资本" prop="registeredCapital">
          <el-input v-model="form.registeredCapital" placeholder="请输入注册资本" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPerson">
          <el-input v-model="form.contactPerson" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="经营范围" prop="businessScope">
          <el-input v-model="form.businessScope" placeholder="请输入经营范围" />
        </el-form-item>
        <el-form-item label="管理部门" prop="managementDept">
          <el-input v-model="form.managementDept" placeholder="请输入管理部门" />
        </el-form-item>
        <el-form-item label="管理部门联系人" prop="managementPerson">
          <el-input v-model="form.managementPerson" placeholder="请输入管理部门联系人" />
        </el-form-item>
        <el-form-item label="营业执照" prop="licenseFileId">
          <el-input v-model="form.licenseFileId" placeholder="请输入营业执照" />
        </el-form-item>
        <el-form-item label="营业执照" prop="licenseFileUrl">
          <el-input v-model="form.licenseFileUrl" placeholder="请输入营业执照" />
        </el-form-item>
        <el-form-item label="营业执照" prop="licenseFileName">
          <el-input v-model="form.licenseFileName" placeholder="请输入营业执照" />
        </el-form-item>
        <el-form-item label="拉黑状态" prop="isBlack">
          <el-select
            v-model="form.isBlack"
            placeholder="请选择拉黑状态"
          >
            <el-option
              v-for="item in isBlackOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContractor, getContractor, delContractor, addContractor, updateContractor } from "@/api/cbs/contractor/basics"

export default {
  name: "AllList",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 承包商信息表格数据
      contractorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 拉黑状态选项
      isBlackOptions: [
        { label: "全部", value: "" },
        { label: "拉黑", value: 1 },
        { label: "正常", value: 0 }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contractorName: null,
        contractorCode: null,
        registerAddress: null,
        officeAddress: null,
        legalPerson: null,
        registeredCapital: null,
        contactPerson: null,
        contactPhone: null,
        enterpriseType: null,
        businessScope: null,
        managementDept: null,
        managementPerson: null,
        licenseFileId: null,
        licenseFileUrl: null,
        licenseFileName: null,
        status: null,
        isBlack: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        contractorName: [
          { required: true, message: "承包商名称不能为空", trigger: "blur" }
        ],
        contractorCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        contactPerson: [
          { required: true, message: "联系人不能为空", trigger: "blur" }
        ],
        contactPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        enterpriseType: [
          { required: true, message: "企业类型不能为空", trigger: "change" }
        ],
        businessScope: [
          { required: true, message: "经营范围不能为空", trigger: "blur" }
        ],
        managementDept: [
          { required: true, message: "管理部门不能为空", trigger: "blur" }
        ],
        managementPerson: [
          { required: true, message: "管理部门联系人不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询承包商信息列表 */
    getList() {
      this.loading = true
      listContractor(this.queryParams).then(response => {
        this.contractorList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        contractorName: null,
        contractorCode: null,
        registerAddress: null,
        officeAddress: null,
        legalPerson: null,
        registeredCapital: null,
        contactPerson: null,
        contactPhone: null,
        enterpriseType: null,
        businessScope: null,
        managementDept: null,
        managementPerson: null,
        licenseFileId: null,
        licenseFileUrl: null,
        licenseFileName: null,
        status: null,
        isBlack: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加承包商信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getContractor(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改承包商信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContractor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addContractor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除承包商信息编号为"' + ids + '"的数据项？').then(function() {
        return delContractor(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/contractor/export', {
        ...this.queryParams
      }, `contractor_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
